package org.tloss.web.editor.sql.editors;

import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.model.IWorkbenchAdapter;
import org.tloss.web.editor.database.editors.jdbc.Column;
import org.tloss.web.editor.utils.Constants;

public class ColumnElement implements IWorkbenchAdapter, IAdaptable {
	Column column;
	IResourceChangeListener listener;

	public ColumnElement(Column column, IResourceChangeListener listener) {
		this.column = column;
		this.listener = listener;

	}

	public Column getColumn() {
		return column;
	}

	/*
	 * (non-Javadoc) Method declared on IAdaptable
	 */
	@SuppressWarnings("rawtypes")
	public Object getAdapter(Class adapter) {
		if (adapter == IWorkbenchAdapter.class)
			return this;
		return null;
	}

	/*
	 * (non-Javadoc) Method declared on IWorkbenchAdapter
	 */
	public ImageDescriptor getImageDescriptor(Object object) {
		return Constants.COLUMN_DESCRIPTOR;
	}

	/*
	 * (non-Javadoc) Method declared on IWorkbenchAdapter
	 */
	public String getLabel(Object o) {
		return column.getColumnName();
	}

	/*
	 * (non-Javadoc) Method declared on IWorkbenchAdapter
	 */
	public Object getParent(Object o) {
		return null;
	}

	/**
	 * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(Object)
	 */
	public Object[] getChildren(Object o) {
		return Constants.EMPTY_ARRAY;
	}

	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (obj instanceof ColumnElement) {
			return ((ColumnElement) obj).getColumn().equals(this.getColumn());
		} else if (obj instanceof Column) {
			return obj.equals(this.getColumn());
		}
		return false;
	}

}
